﻿using System.Windows.Input;
using Cinch;
using TeamTasker.Contracts;

namespace TeamTasker.Client.Presentation.ViewModels
{
    public class AddEditTaskViewModel : ViewModelBase
    {
        public AddEditTaskViewModel()
        {
            Task = new Task();
            SaveTaskCommand = new SimpleCommand() {ExecuteDelegate = SaveChanges};
            CancelCommand = new SimpleCommand() {ExecuteDelegate = CancelChanges};
        }

        public HierarchicalTaskListViewModel ParentViewModel { get; set; }

        public Task Task { get; set; }

        public ICommand SaveTaskCommand { get; set; }

        public ICommand CancelCommand { get; set; }

        private void CancelChanges(object obj)
        {
            //Clear all fields...
            if (ParentViewModel != null)
            {
                Mediator.NotifyColleagues("GoToTaskTreeView", ParentViewModel);
            }
        }

        private void SaveChanges(object obj)
        {
            //Add new task in tree
            if (ParentViewModel != null)
            {
                Mediator.NotifyColleagues("GoToTaskTreeView", ParentViewModel);
            }
        }
    }
}
